package code.D1212;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;

/**
 * author : yeswater
 * date : 2023/12/12
 * <p>
 * 子集
 * 07 50 -
 */

public class T078 {
    HashSet<List<Integer>> res = new HashSet<>();
    LinkedList<Integer> path = new LinkedList<>();

    public List<List<Integer>> subsets(int[] nums) {
        res.add(new ArrayList<>());
        for (int i = 0; i < nums.length; i++) {
            func(nums, i);
        }
        return new ArrayList<>(res);
    }

    public void func(int[] nums, int index) {
        if (index > nums.length - 1) {
            res.add(new ArrayList<>(path));
            return;
        }
        for (int i = index; i < nums.length; i++) {
            path.add(nums[i]);
            res.add(new ArrayList<>(path));
            func(nums, i + 1); // i 是全排序; index 是有序排序
            path.removeLast();
        }
    }
}
